package com.unicom.examine.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unicom.examine.mapper.SalesDetailMapper;
import com.unicom.examine.model.SalesDetail;
import com.unicom.examine.service.SalesDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SalesDetailServiceImpl implements SalesDetailService {

	@Autowired
	private SalesDetailMapper salesDetailMapper;

	@Override
	public List<SalesDetail> getall() {
		List<SalesDetail> items = salesDetailMapper.selectByExample(null);
		return items;
	}

	@Override
	public Map<String,Object> getall(int page, int rows) {

		Map<String, Object> map = new HashMap<>();

		PageHelper.startPage(page, rows);
		List<SalesDetail> items = salesDetailMapper.selectByExample(null);
		PageInfo<SalesDetail> pageInfo = new PageInfo<>(items);
		System.out.println(pageInfo);
		map.put("list", items);
		map.put("total", pageInfo.getTotal());
		return map;
	}

	@Override
	public void add(SalesDetail items) {
		salesDetailMapper.insert(items);
	}

	@Override
	public SalesDetail get(int id) {
		return salesDetailMapper.selectByPrimaryKey(id);
	}

	@Override
	@Transactional
	public void delete(int id) {
		salesDetailMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void update(SalesDetail item) {
		salesDetailMapper.updateByPrimaryKeySelective(item);
	}


}
